package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RcLink;
import com.ruoyi.system.service.IRcLinkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业链接Controller
 *
 * @author ruoyi
 * @date 2023-11-14
 */
@RestController
@RequestMapping("/basic/link")
public class RcLinkController extends BaseController
{
    @Autowired
    private IRcLinkService rcLinkService;

    /**
     * 查询企业链接列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RcLink rcLink)
    {
        startPage();
        List<RcLink> list = rcLinkService.selectRcLinkList(rcLink);
        return getDataTable(list);
    }

    /**
     * 导出企业链接列表
     */
    @Log(title = "企业链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RcLink rcLink)
    {
        List<RcLink> list = rcLinkService.selectRcLinkList(rcLink);
        ExcelUtil<RcLink> util = new ExcelUtil<RcLink>(RcLink.class);
        util.exportExcel(response, list, "企业链接数据");
    }

    /**
     * 获取企业链接详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rcLinkService.selectRcLinkById(id));
    }

    /**
     * 新增企业链接
     */
    @Log(title = "企业链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RcLink rcLink)
    {
        rcLink.setCreateBy(getUsername());
        return toAjax(rcLinkService.insertRcLink(rcLink));
    }

    /**
     * 修改企业链接
     */
    @Log(title = "企业链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RcLink rcLink)
    {
        rcLink.setUpdateBy(getUsername());
        return toAjax(rcLinkService.updateRcLink(rcLink));
    }

    /**
     * 删除企业链接
     */
    @Log(title = "企业链接", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rcLinkService.deleteRcLinkByIds(ids));
    }
}
